package aWebUrls

import (
	getVideo "awang/aWeb/aWebViews/getVideos"
	"net/http"

	"github.com/gin-gonic/gin"
)

func WebRoot(router *gin.Engine) {
	router.LoadHTMLGlob("templates/aWeb/*")
	router_root := router.Group("")
	a := make(map[string]interface{})
	a["message"] = "pong"
	{
		router_root.GET("/ping", func(c *gin.Context) {
			c.JSON(200, a)
		})

		router_root.GET("/", web_index)
		router_root.GET("/index", web_index)
		router_root.GET("/web/:web_name", web_get) // job为无限长
		// router_root.GET("/:web_name/*job", web_index) // job为无限长
	}
}

func WebApi(router *gin.Engine) {
	router_api := router.Group("/api")
	{
		router_api.GET("/get_video", getVideo.GetVideos)
		router_api.GET("/get_path_video", getVideo.GetPathVideos)
		router_api.GET("/get_visit_times", getVideo.GetVisitTimes)

		router_api.POST("/upload_video", getVideo.UploadVideo)
	}
}

func web_index(c *gin.Context) {
	c.HTML(http.StatusOK, "index.html", gin.H{
		"title": "Main website",
	})
}

func web_get(c *gin.Context) {
	web_name := c.Param("web_name")
	// job := c.Param("job")
	c.HTML(http.StatusOK, web_name+".html", gin.H{
		"title": "Main website",
	})
}
